package com.alipay.pay.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.demo.trade.service.AlipayTradeService;
import com.alipay.demo.trade.service.impl.AlipayTradeServiceImpl;


/**
 * 
 * 初始化bean
 * 
 * @author xxoo
 *
 */
@Configuration
public class AlipayConfiguration {
	
	@Autowired
	private AlipayConfig alipayConfig;
	
	@Bean 
	public AlipayClient alipayClient() {
		 return new DefaultAlipayClient(
				 alipayConfig.getGatewayUrl(),
				 alipayConfig.getAppid(),
				 alipayConfig.getMerchantPrivateKey(),
				 alipayConfig.getFormate(),
				 alipayConfig.getCharset(),
				 alipayConfig.getAlipayPublicKey(),
				 alipayConfig.getSignType()
		);
	}
	
	@Bean
    public AlipayTradeService alipayTradeService() {
        return new AlipayTradeServiceImpl.ClientBuilder()
                .setGatewayUrl(alipayConfig.getGatewayUrl())
                .setAppid(alipayConfig.getAppid())
                .setPrivateKey(alipayConfig.getMerchantPrivateKey())
                .setAlipayPublicKey(alipayConfig.getAlipayPublicKey())
                .setSignType(alipayConfig.getSignType())
                .build();
    }
}
